package Chinese.Education.Identify.controller;

import Chinese.Education.Identify.pojo.Teacher;
import Chinese.Education.Identify.service.TeacherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;
    @RequestMapping(value = "/select" , method = RequestMethod.GET)
    public Map<String, Object> selectTeacher(@RequestParam(value = "page",  defaultValue = "1")  int page,
                                             @RequestParam(value = "limit", defaultValue = "10") int limit,
                                             String teacherId,
                                             String teacherName)
        {
            Map<String, Object> map = teacherService.selectTeacher(page, limit, teacherId,teacherName);
            return map;
    }

    @RequestMapping(value = "/delete" , method = RequestMethod.POST)
    public Map<String, Object> deleteTeacher(@RequestBody Teacher teacher)
        {
            return teacherService.deleteTeacher(teacher);
        }

        @RequestMapping(value = "/insert" , method = RequestMethod.POST)
        public Map<String, Object> insertTeacher(@RequestBody Teacher teacher)
            {
                return teacherService.insertTeacher(teacher);
            }

            @RequestMapping(value = "/update" , method = RequestMethod.POST)
            public Map<String, Object> updateTeacher(@RequestBody Teacher teacher)
                {
                    return teacherService.updateTeacher(teacher);
                }

    @PutMapping("/{id}/description")
    public void updateDescription(@PathVariable String id, @RequestBody Map<String, String> payload) {
        teacherService.updateDescription(id, payload.get("description"));
    }
}
